<?php

namespace app\admin\controller\ball;

use app\BaseController;
use think\facade\Db; // 数据库的链接

class Debris extends BaseController
{
    public function getlist()
    {
        $get = input();

        // 分页
        $pageSize = $get['pageSize'] > 100 ? 100 : $get['pageSize'];
        $page = $get['pageNo'];
       

        // 操作类型
        if (!empty(@$get['is_status'])) {
            $sql[] = ['a.is_status', '=', $get['is_status'] - 1];
        }

        // 查询条件 模糊查询
        if (!empty(@$get['phone'])) {
            $sql[] = ['b.phone', 'LIKE', "%" . $get['phone'] . "%"];
        }
        
        // 使用table分页查询数据表wechart_customer_info
        $list = Db::name('ball_debris')
            ->alias('a')
            ->join('user b','a.uid = b.id')
            ->join('ball_type c','a.bid = c.id')
            ->field("a.*,b.phone,c.name as bname, FROM_UNIXTIME(a.obtain_time,'%Y-%m-%d %H:%i:%s') as obtain_time,FROM_UNIXTIME(a.usage_time,'%Y-%m-%d %H:%i:%s') as usage_time")
            ->where(@$sql)
            ->order('a.id DESC')
            ->paginate([
                'list_rows' => $pageSize,
                'page' => $page
            ])
            ->toArray();
        // 返回数据
        return array(
            'code' => 200,
            'msg' => 'success',
            'data' => $list,
        );
    }
}